local baobian = fk.CreateSkill {
  name = "mini__baobian",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["mini__baobian"] = "豹变",
  [":mini__baobian"] = "锁定技，若你的体力值：<br>为4，你视为拥有技能〖困奋〗；<br>"..
  "不大于3，你视为拥有技能〖挑衅〗；<br>不大于2，你视为拥有技能〖咆哮〗；<br>为1，你视为拥有技能〖神速〗。",
}

local function baobianChange(player, hp, skill_name)
  local room = player.room
  local skills = player.tag[baobian.name] or {}
  if player.hp <= hp then
    if not table.contains(skills, skill_name) then
      room:handleAddLoseSkills(player, skill_name, nil, false, true)
      table.insert(skills, skill_name)
    end
  else
    if table.contains(skills, skill_name) then
      room:handleAddLoseSkills(player, "-"..skill_name, nil, false, true)
      table.removeOne(skills, skill_name)
    end
  end
  player.tag[baobian.name] = skills
end

local spec = {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(baobian.name, true)
  end,
  on_refresh = function(self, event, target, player, data)
    baobianChange(player, 1, "mini__shensu")
    baobianChange(player, 2, "os_ex__paoxiao")
    baobianChange(player, 3, "m_ex__tiaoxin")
    baobianChange(player, 4, "mini__kunfen")
  end,
}

baobian:addEffect(fk.HpChanged, spec)
baobian:addEffect(fk.MaxHpChanged, spec)
baobian:addEffect(fk.EventAcquireSkill, spec)

baobian:addLoseEffect(function (self, player, is_death)
  local skills = player.tag[baobian.name]
  player.room:handleAddLoseSkills(player, "-"..table.concat(skills, "|"), nil, false, true)
  player.tag[baobian.name] = nil
end)


return baobian
